package usersManagement.service;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;
import org.slf4j.Logger;
import usersManagement.model.Organization;
import usersManagement.model.Shipment;
import usersManagement.model.User;
import usersManagement.repository.ShipmentRepository;
import usersManagement.repository.UserRepository;
import usersManagement.security.LoggedUser;
import usersManagement.util.AppLog;

import javax.ejb.Stateless;
import javax.inject.Inject;
import javax.validation.ConstraintViolationException;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import java.io.Serializable;
import java.net.URI;
import java.util.List;

/**
 * User: eluibon
 * Date: 11/12/12
 * Time: 14.06
 */
@Stateless
public class ShipmentService implements Serializable {
// ------------------------------ FIELDS ------------------------------

    private static final long serialVersionUID = -4715457013984101366L;

    @Inject @AppLog private Logger log;
    @Inject private ShipmentRepository shipmentRepository;
    @Inject @LoggedUser User loggedUser ;

// -------------------------- OTHER METHODS --------------------------

    public List<Shipment> findAvailableShipments() {

        return shipmentRepository.findAvailableShipments(loggedUser.getOrganization());
    }

    public void assignOwnershipToLoggedUser(Shipment shipment) {

        shipment.assignOwnershipTo(loggedUser) ;
        shipmentRepository.save(shipment) ;
    }
}
